package com.qf.ssm.controller;

import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.entity.Product;
import com.qf.ssm.service.ProductAppService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
   @author 86155
   @ClassName: com.qf.ssm.controller.ProductAppController
   @Description: 该类的功能描述
   @date: 2021/10/12 14:47 
*/

@RestController
@RequestMapping("/product/app")
public class ProductAppController {
    @Resource
    private ProductAppService productAppService;


    /**
     * 首页展示今日优选的所有商品
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/preferred")
    public ResponseResult<List<Product>> preferredProduct(@RequestParam(defaultValue = "1") Integer page,
                                                          @RequestParam(defaultValue = "10") Integer size) {
        List<Product> products = productAppService.findPreferred(page, size);
        return ResponseResult.success(products);
    }

    /**
     * 首页点击查看优选商品的详情信息
     * @param pid
     * @return
     */
    @GetMapping("/preferred/product/{pid}")
    public ResponseResult<Product> findProductByPid(@PathVariable("pid") Long pid) {
        Product product = productAppService.findProductByPid(pid);
        return ResponseResult.success(product);
    }
}
